package benny_driving_ser.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBUtil {
	private DBUtil() {

	}

	private static class DBUtilHolder {
		private static DBUtil instance = new DBUtil();
	}

	public static DBUtil getInstance() {
		return DBUtilHolder.instance;
	}

	public void closeConnection(Connection connection) {
		try {
			connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public Connection openConnection() {
		Properties prop = new Properties();
		String driver = null;
		String url = null;
		String username = null;
		String password = null;

		try {
//			url = "jdbc:mysql://localhost/bddb?useUnicode=true&characterEncoding=utf-8&user=bddb&password=12345678";
			url = "jdbc:mysql://localhost/hdm0380482_db?useUnicode=true&characterEncoding=utf-8&user=root&password=&zeroDateTimeBehavior=round";
			
			
//			url = "jdbc:mysql://localhost/bddb?useUnicode=true&characterEncoding=utf-8&user=bddb&password=12345678&zeroDateTimeBehavior=round";
			
			
			
//			url = "jdbc:mysql://112.124.33.63:3306/bddb?useUnicode=true&characterEncoding=utf-8&user=bddb&password=12345678";
//			url = "jdbc:mysql://112.124.33.63:3306/bddb?useUnicode=true&characterEncoding=utf-8&user=bddb&password=12345678&zeroDateTimeBehavior=round";
			// url =
			// "jdbc:mysql://localhost/bddb?useUnicode=true&characterEncoding=utf-8&user=root&password=";

			// prop.load(this.getClass().getClassLoader()
			// .getResourceAsStream("DBConfig.properties"));

			// driver = prop.getProperty("driver");
			// url = prop.getProperty("url");
			// username = prop.getProperty("username");
			// password = prop.getProperty("password");
			// Class.forName(driver).newInstance();
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			return DriverManager.getConnection(url);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}
}
